package com.zhouyong.leetcode.大数相加;

/**
 * @Author 99
 * @Date 2022/10/12 9:57
 * @Version 1.0
 */
public class Test {

    // 一个超出了int和long类型的正数如何相加

    public static void main(String[] args) {

//        int a = 11111111111;
//        int b = 22222222222;
        System.out.println(bigNumberAdd("249", "5649"));
    }

    public static String bigNumberAdd(String s1, String s2) {
        int i = s1.length() - 1, j = s2.length() - 1, count = 0;
        StringBuilder sb = new StringBuilder();
        while (i >= 0 || j >= 0 || count != 0) {
            int x = i >= 0 ? s1.charAt(i) - '0' : 0;
            int y = j >= 0 ? s2.charAt(j) - '0' : 0;
            int res = x + y + count;
            sb.append(res % 10);
            count = res / 10;
            i--;
            j--;
        }
        return sb.reverse().toString();
    }
}
